package com.jackrain.nea.omslocal.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jackrain.nea.web.query.QueryEngine;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.Date;

/**
 * @Discription: Created with IntelliJ IDEA.
 * @Author cs
 * @Date 2017/10/24 9:34
 */
@Slf4j
@Component
public class ChangeCloudStatusService {

    /**
     * 修改云仓订单状态
     *
     * @param jsonArray
     */
    public void changeStatusSuc(JSONArray jsonArray) {

        // EDIFLAG = 9 时, 该订单信息已经发送   EDIFLAG = 90 时 ,同步失败 YSN_NOTICESITEM
        String sql = "update ysn_noticesitem set EDIFLAG = 99,READ_TIME = ? ,READ_TIMES = 1 where id = ? ";
        try {

            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject tempObj = JSONObject.parseObject(jsonArray.get(i).toString());
                int id = tempObj.getIntValue("ID");
                Date nowTime = new Date(System.currentTimeMillis());
                QueryEngine.getInstance().executeUpdate(sql, new Object[]{nowTime,id});
            }
        } catch (Exception e) {
            // 修改状态失败
            log.error("修改云仓订单同步状态失败  " +e.getMessage());
        }

    }


    public void changeStatusFail(JSONArray jsonArray) {

        // EDIFLAG = 99 时, 该订单信息已经发送   EDIFLAG = 90 时 ,同步失败
        String sql = "update YSN_NOTICESITEM set EDIFLAG = 90,RESULTS=? where id = ? ";
        JSONArray paramArr = new JSONArray();
        try {

            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject tempObj = JSONObject.parseObject(jsonArray.get(i).toString());
                int id = tempObj.getIntValue("ID");
                QueryEngine.getInstance().executeUpdate(sql, new Object[]{id});
            }
        } catch (Exception e) {
            // 修改状态失败
            log.error("修改云仓订单同步状态失败"+e.getMessage());
        }

    }


}
